<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>dlarrj.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="DLARRJ.1"></a><a href="dlarrj.f.html#DLARRJ.1">DLARRJ</a>( N, D, E2, IFIRST, ILAST,
     $                   RTOL, OFFSET, W, WERR, WORK, IWORK,
     $                   PIVMIN, SPDIAM, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK auxiliary routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            IFIRST, ILAST, INFO, N, OFFSET
      DOUBLE PRECISION   PIVMIN, RTOL, SPDIAM
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            IWORK( * )
      DOUBLE PRECISION   D( * ), E2( * ), W( * ),
     $                   WERR( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Given the initial eigenvalue approximations of T, <a name="DLARRJ.22"></a><a href="dlarrj.f.html#DLARRJ.1">DLARRJ</a>
</span><span class="comment">*</span><span class="comment">  does  bisection to refine the eigenvalues of T,
</span><span class="comment">*</span><span class="comment">  W( IFIRST-OFFSET ) through W( ILAST-OFFSET ), to more accuracy. Initial
</span><span class="comment">*</span><span class="comment">  guesses for these eigenvalues are input in W, the corresponding estimate
</span><span class="comment">*</span><span class="comment">  of the error in these guesses in WERR. During bisection, intervals
</span><span class="comment">*</span><span class="comment">  [left, right] are maintained by storing their mid-points and
</span><span class="comment">*</span><span class="comment">  semi-widths in the arrays W and WERR respectively.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The order of the matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  D       (input) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">          The N diagonal elements of T.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  E2      (input) DOUBLE PRECISION array, dimension (N-1)
</span><span class="comment">*</span><span class="comment">          The Squares of the (N-1) subdiagonal elements of T.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  IFIRST  (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The index of the first eigenvalue to be computed.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ILAST   (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The index of the last eigenvalue to be computed.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RTOL   (input) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">          Tolerance for the convergence of the bisection intervals.
</span><span class="comment">*</span><span class="comment">          An interval [LEFT,RIGHT] has converged if
</span><span class="comment">*</span><span class="comment">          RIGHT-LEFT.LT.RTOL*MAX(|LEFT|,|RIGHT|).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  OFFSET  (input) INTEGER
</span><span class="comment">*</span><span class="comment">          Offset for the arrays W and WERR, i.e., the IFIRST-OFFSET
</span><span class="comment">*</span><span class="comment">          through ILAST-OFFSET elements of these arrays are to be used.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  W       (input/output) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">          On input, W( IFIRST-OFFSET ) through W( ILAST-OFFSET ) are
</span><span class="comment">*</span><span class="comment">          estimates of the eigenvalues of L D L^T indexed IFIRST through
</span><span class="comment">*</span><span class="comment">          ILAST.
</span><span class="comment">*</span><span class="comment">          On output, these estimates are refined.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WERR    (input/output) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">          On input, WERR( IFIRST-OFFSET ) through WERR( ILAST-OFFSET ) are
</span><span class="comment">*</span><span class="comment">          the errors in the estimates of the corresponding elements in W.
</span><span class="comment">*</span><span class="comment">          On output, these errors are refined.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace) DOUBLE PRECISION array, dimension (2*N)
</span><span class="comment">*</span><span class="comment">          Workspace.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  IWORK   (workspace) INTEGER array, dimension (2*N)
</span><span class="comment">*</span><span class="comment">          Workspace.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  PIVMIN  (input) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">          The minimum pivot in the Sturm sequence for T.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  SPDIAM  (input) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">          The spectral diameter of T.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          Error flag.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Based on contributions by
</span><span class="comment">*</span><span class="comment">     Beresford Parlett, University of California, Berkeley, USA
</span><span class="comment">*</span><span class="comment">     Jim Demmel, University of California, Berkeley, USA
</span><span class="comment">*</span><span class="comment">     Inderjit Dhillon, University of Texas, Austin, USA
</span><span class="comment">*</span><span class="comment">     Osni Marques, LBNL/NERSC, USA
</span><span class="comment">*</span><span class="comment">     Christof Voemel, University of California, Berkeley, USA
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      DOUBLE PRECISION   ZERO, ONE, TWO, HALF
      PARAMETER        ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0,
     $                   HALF = 0.5D0 )
      INTEGER   MAXITR
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            CNT, I, I1, I2, II, ITER, J, K, NEXT, NINT,
     $                   OLNINT, P, PREV, SAVI1
      DOUBLE PRECISION   DPLUS, FAC, LEFT, MID, RIGHT, S, TMP, WIDTH
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          ABS, MAX
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span>      MAXITR = INT( ( LOG( SPDIAM+PIVMIN )-LOG( PIVMIN ) ) /
     $           LOG( TWO ) ) + 2
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Initialize unconverged intervals in [ WORK(2*I-1), WORK(2*I) ].
</span><span class="comment">*</span><span class="comment">     The Sturm Count, Count( WORK(2*I-1) ) is arranged to be I-1, while
</span><span class="comment">*</span><span class="comment">     Count( WORK(2*I) ) is stored in IWORK( 2*I ). The integer IWORK( 2*I-1 )
</span><span class="comment">*</span><span class="comment">     for an unconverged interval is set to the index of the next unconverged
</span><span class="comment">*</span><span class="comment">     interval, and is -1 or 0 for a converged interval. Thus a linked
</span><span class="comment">*</span><span class="comment">     list of unconverged intervals is set up.
</span><span class="comment">*</span><span class="comment">
</span>
      I1 = IFIRST
      I2 = ILAST
<span class="comment">*</span><span class="comment">     The number of unconverged intervals
</span>      NINT = 0
<span class="comment">*</span><span class="comment">     The last unconverged interval found
</span>      PREV = 0
      DO 75 I = I1, I2
         K = 2*I
         II = I - OFFSET
         LEFT = W( II ) - WERR( II )
         MID = W(II)
         RIGHT = W( II ) + WERR( II )
         WIDTH = RIGHT - MID
         TMP = MAX( ABS( LEFT ), ABS( RIGHT ) )

<span class="comment">*</span><span class="comment">        The following test prevents the test of converged intervals
</span>         IF( WIDTH.LT.RTOL*TMP ) THEN
<span class="comment">*</span><span class="comment">           This interval has already converged and does not need refinement.
</span><span class="comment">*</span><span class="comment">           (Note that the gaps might change through refining the
</span><span class="comment">*</span><span class="comment">            eigenvalues, however, they can only get bigger.)
</span><span class="comment">*</span><span class="comment">           Remove it from the list.
</span>            IWORK( K-1 ) = -1
<span class="comment">*</span><span class="comment">           Make sure that I1 always points to the first unconverged interval
</span>            IF((I.EQ.I1).AND.(I.LT.I2)) I1 = I + 1
            IF((PREV.GE.I1).AND.(I.LE.I2)) IWORK( 2*PREV-1 ) = I + 1
         ELSE
<span class="comment">*</span><span class="comment">           unconverged interval found
</span>            PREV = I
<span class="comment">*</span><span class="comment">           Make sure that [LEFT,RIGHT] contains the desired eigenvalue
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Do while( CNT(LEFT).GT.I-1 )
</span><span class="comment">*</span><span class="comment">
</span>            FAC = ONE
 20         CONTINUE
            CNT = 0
            S = LEFT
            DPLUS = D( 1 ) - S
            IF( DPLUS.LT.ZERO ) CNT = CNT + 1
            DO 30 J = 2, N
               DPLUS = D( J ) - S - E2( J-1 )/DPLUS
               IF( DPLUS.LT.ZERO ) CNT = CNT + 1
 30         CONTINUE
            IF( CNT.GT.I-1 ) THEN
               LEFT = LEFT - WERR( II )*FAC
               FAC = TWO*FAC
               GO TO 20
            END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Do while( CNT(RIGHT).LT.I )
</span><span class="comment">*</span><span class="comment">
</span>            FAC = ONE
 50         CONTINUE
            CNT = 0
            S = RIGHT
            DPLUS = D( 1 ) - S
            IF( DPLUS.LT.ZERO ) CNT = CNT + 1
            DO 60 J = 2, N
               DPLUS = D( J ) - S - E2( J-1 )/DPLUS
               IF( DPLUS.LT.ZERO ) CNT = CNT + 1
 60         CONTINUE
            IF( CNT.LT.I ) THEN
               RIGHT = RIGHT + WERR( II )*FAC
               FAC = TWO*FAC
               GO TO 50
            END IF
            NINT = NINT + 1
            IWORK( K-1 ) = I + 1
            IWORK( K ) = CNT
         END IF
         WORK( K-1 ) = LEFT
         WORK( K ) = RIGHT
 75   CONTINUE


      SAVI1 = I1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Do while( NINT.GT.0 ), i.e. there are still unconverged intervals
</span><span class="comment">*</span><span class="comment">     and while (ITER.LT.MAXITR)
</span><span class="comment">*</span><span class="comment">
</span>      ITER = 0
 80   CONTINUE
      PREV = I1 - 1
      I = I1
      OLNINT = NINT

      DO 100 P = 1, OLNINT
         K = 2*I
         II = I - OFFSET
         NEXT = IWORK( K-1 )
         LEFT = WORK( K-1 )
         RIGHT = WORK( K )
         MID = HALF*( LEFT + RIGHT )

<span class="comment">*</span><span class="comment">        semiwidth of interval
</span>         WIDTH = RIGHT - MID
         TMP = MAX( ABS( LEFT ), ABS( RIGHT ) )

         IF( ( WIDTH.LT.RTOL*TMP ) .OR.
     $      (ITER.EQ.MAXITR) )THEN
<span class="comment">*</span><span class="comment">           reduce number of unconverged intervals
</span>            NINT = NINT - 1
<span class="comment">*</span><span class="comment">           Mark interval as converged.
</span>            IWORK( K-1 ) = 0
            IF( I1.EQ.I ) THEN
               I1 = NEXT
            ELSE
<span class="comment">*</span><span class="comment">              Prev holds the last unconverged interval previously examined
</span>               IF(PREV.GE.I1) IWORK( 2*PREV-1 ) = NEXT
            END IF
            I = NEXT
            GO TO 100
         END IF
         PREV = I
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Perform one bisection step
</span><span class="comment">*</span><span class="comment">
</span>         CNT = 0
         S = MID
         DPLUS = D( 1 ) - S
         IF( DPLUS.LT.ZERO ) CNT = CNT + 1
         DO 90 J = 2, N
            DPLUS = D( J ) - S - E2( J-1 )/DPLUS
            IF( DPLUS.LT.ZERO ) CNT = CNT + 1
 90      CONTINUE
         IF( CNT.LE.I-1 ) THEN
            WORK( K-1 ) = MID
         ELSE
            WORK( K ) = MID
         END IF
         I = NEXT

 100  CONTINUE
      ITER = ITER + 1
<span class="comment">*</span><span class="comment">     do another loop if there are still unconverged intervals
</span><span class="comment">*</span><span class="comment">     However, in the last iteration, all intervals are accepted
</span><span class="comment">*</span><span class="comment">     since this is the best we can do.
</span>      IF( ( NINT.GT.0 ).AND.(ITER.LE.MAXITR) ) GO TO 80
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     At this point, all the intervals have converged
</span>      DO 110 I = SAVI1, ILAST
         K = 2*I
         II = I - OFFSET
<span class="comment">*</span><span class="comment">        All intervals marked by '0' have been refined.
</span>         IF( IWORK( K-1 ).EQ.0 ) THEN
            W( II ) = HALF*( WORK( K-1 )+WORK( K ) )
            WERR( II ) = WORK( K ) - W( II )
         END IF
 110  CONTINUE
<span class="comment">*</span><span class="comment">
</span>
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="DLARRJ.278"></a><a href="dlarrj.f.html#DLARRJ.1">DLARRJ</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
